<template>
    <div ref="chart" style="width: 100%; height: 400px;"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
    props: {
        data: Object
    },
    mounted() {
        this.chart = echarts.init(this.$refs.chart);
        this.updateChart();
    },
    watch: {
        data: {
            deep: true,
            handler() {
                this.updateChart();
            }
        }
    },
    methods: {
        updateChart() {
            this.chart.setOption({
                tooltip: {
                    trigger: 'item'
                },
                series: [
                    {
                        type: 'pie',
                        radius: '50%',
                        data: this.data.labels.map((label, index) => ({
                            value: this.data.datasets[0].data[index],
                            name: label
                        })),
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            });
        }
    }
}
</script> 